<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
  var arr =  ['a','a','a','b','b','c','c','c','c','d','d','d','d'] ;
  arr.sort();
  var obj = new Object();
  var curChar = arr[0];
  var curLength = 1;
  for(var i = 1; i < arr.length; i++ ){
    var key = arr[i];
    if(curChar == key){
      curLength += 1;
    }else{
      obj[curChar] = curLength; 
      curChar = key;
      curLength = 1;
    }
  }
  obj[curChar] = curLength;
  console.log(obj) // {a: 3, b: 2, c: 4, d: 4}
</script>
</html>